<template>
  <div class="transferManagement">
    <div class="topBar">
      <div class="searchBar">
        <el-form
          :model="queryParams"
          ref="queryForm"
          size="small"
          :inline="true"
          label-width="80px">
          <el-form-item label="申请号" prop="number">
            <el-input
              v-model="queryParams.number"
              placeholder="请输入申请号"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="专利类型" prop="patentType">
            <el-select v-model="queryParams.patentType" placeholder="请选择专利类型" clearable>
              <el-option
                v-for="dict in dict.type.patent_type"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="申请人类型" prop="filingType" style="white-space: nowrap;">
            <el-select v-model="queryParams.filingType" placeholder="请选择申请人类型" clearable style="white-space: nowrap;">
              <el-option
                v-for="dict in dict.type.filing_type"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>
      </div>
      <div class="operateBar">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:transference:add']"
        >新增</el-button>
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:transference:remove']"
        >删除</el-button>
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:transference:export']"
        >导出</el-button>
      </div>
    </div>
    <el-table
      stripe
      height="100%"
      style="width: 100%"
      :data="transferenceList"
      v-loading="loading"
      @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="50" align="center" />
      <el-table-column label="专利类型"  prop="patentType" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.patent_type" :value="scope.row.patentType"/>
        </template>
      </el-table-column>
      <el-table-column
        width="130"
        label="申请号"
        prop="number" />
      <el-table-column
        width="300"
        label="发明名称"
        prop="name"
        show-overflow-tooltip/>
      <el-table-column label="申请日" prop="filingTime" >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.filingTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="授权日" prop="empowerTime" >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.empowerTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="申请人类型" prop="filingType" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.filing_type" :value="scope.row.filingType"/>
        </template>
      </el-table-column>
      <el-table-column label="案件领域" prop="caseType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.case_type" :value="scope.row.caseType"/>
        </template>
      </el-table-column>
      <el-table-column label="简要" prop="point" show-overflow-tooltip/>
      <el-table-column label="价格" prop="amount" />
      <el-table-column label="发布人" prop="nikeName" />
      <el-table-column label="是否交易" prop="flag">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.flag" :value="scope.row.flag"/>
        </template>
      </el-table-column>
      <el-table-column label="案件状态类型" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.case_status" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="120">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:transference:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:transference:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改转让对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="open"
      width="800px"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      append-to-body
      :before-close="closeEvent">
      <el-form
        ref="form"
        :model="form"
        :rules="rules"
        label-width="120px">
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="专利类型" prop="patentType">
              <el-select
                style="width: 100%"
                v-model="form.patentType"
                placeholder="请选择专利类型">
                <el-option
                  v-for="dict in dict.type.patent_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="申请号" prop="number">
              <el-input v-model="form.number" placeholder="请输入申请号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="申请日" prop="filingTime">
              <el-date-picker
                style="width: 100%"
                clearable
                v-model="form.filingTime"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="请选择申请日">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="授权日" prop="empowerTime">
              <el-date-picker
                style="width: 100%"
                clearable
                v-model="form.empowerTime"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="请选择授权日">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="申请人类型" prop="filingType">
              <el-select
                style="width: 100%"
                v-model="form.filingType"
                placeholder="请选择申请人类型">
                <el-option
                  v-for="dict in dict.type.filing_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="案件领域" prop="caseType">
              <el-select
                style="width: 100%"
                v-model="form.caseType"
                placeholder="请选择案件领域">
                <el-option
                  v-for="dict in dict.type.case_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="价格" prop="amount">
              <el-input disabled v-model="form.amount" placeholder="请输入价格" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="发布人" prop="nikeName">
              <el-input disabled v-model="form.nikeName" placeholder="请输入发布人" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="显示是否已交易" prop="flag">
              <el-select
                style="width: 100%"
                v-model="form.flag"
                placeholder="请选显示是否已交易">
                <el-option
                  v-for="dict in dict.type.flag"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="案件状态类型" prop="status">
              <el-select
                style="width: 100%"
                v-model="form.status"
                placeholder="请选择案件状态类型">
                <el-option
                  v-for="dict in dict.type.case_status"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="发明名称" prop="name">
          <el-input v-model="form.name" placeholder="请输入发明名称" />
        </el-form-item>
        <el-form-item label="简要" prop="point">
          <el-input v-model="form.point" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="closeEvent">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listTransference, getTransference, delTransference, addTransference, updateTransference } from "@/api/transferManagement";
export default {
  name: "Transference",
  dicts: ['patent_type', 'case_type', 'case_status', 'filing_type','patent_field','flag'],
  data() {
    return {
      queryParams: {
        number: null,
        patentType: null,
        filingType: null,
        pageNum: 1,
        pageSize: 10,
      },

      transferenceList: [],
      total: 0,
      loading: true,
      ids: [],
      multiple: true,

      title: "",
      open: false,
      form: {
        id: null,
        patentType: null,
        number: null,
        name: null,
        filingTime: null,
        empowerTime: null,
        filingType: null,
        caseType: null,
        point: null,
        amount: null,
        createTime: null,
        userId: null,
        flag: null,
        status: null
      },
      rules: {}
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询转让列表 */
    getList() {
      this.loading = true;
      listTransference(this.queryParams).then(response => {
        this.transferenceList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.multiple = !selection.length
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除转让编号为"' + ids + '"的数据项？').then(function() {
        return delTransference(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/transference/export', {
        ...this.queryParams
      }, `transference_${new Date().getTime()}.xlsx`)
    },
    // 取消按钮
    closeEvent() {
      this.$refs['form'].resetFields();
      this.open = false;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.open = true;
      this.title = "添加转让";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      const id = row.id
      getTransference(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改转让";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateTransference(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.closeEvent();
              this.getList();
            });
          } else {
            addTransference(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.closeEvent();
              this.getList();
            });
          }
        }
      });
    },
  }
};
</script>
<style lang="scss" scoped>
div.transferManagement {
  div.topBar {
    height: 36px;
    margin-bottom: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    div.searchBar {
      .el-form-item {
        margin-bottom: 0;
      }
    }
  }
}
</style>
